﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ZLCMS.Business;
using ZLCMS.Data.Accessor;
using System.Collections;
using ZLCMS.Data.Model;
using ZLCMS.Business.Config;
using ZLCMS.Business.DwzFrame;
using System.Reflection;
using ZLCMS.Web.Code;

namespace ZLCMS.Web.Example.MessageBoard
{
    public partial class MessageAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void bt_commit_Click(object sender, EventArgs e)
        {
            if (!CheckCode())
            {
                lt_result.Text = "输入验证码有误！";
                //ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='JavaScript'>alert('输入验证码有误！');</script>");
            }
            else
            {
                AddMessage();
                lt_result.Text = "操作成功！我们将会尽快与您取得联系！";
                //Page.Response.Write("<script language=javascript>alert('操作成功。');window.open(window.location.href, '_self')</script>");
            }
        }

        private Boolean CheckCode()
        {
            if (Session[GlobalSessionString.UserCheckCode] == null)
            {
                return false;
            }

            return (Session[GlobalSessionString.UserCheckCode].ToString() == tb_check.Text);
        }

        private void AddMessage()
        {
            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                MessageInfo message = new MessageInfo();

                message.Author = tb_author.Text;
                message.Title = tb_title.Text;
                message.Qq = tb_qq.Text;
                message.Phone = tb_phone.Text;
                message.Addr = tb_addr.Text;
                message.Content = ta_content.Value;
                message.Addtime = DateTime.Now;
                message.Type = "WORD";
                message.Status = "0";

                session.Save(message);
                session.Flush();
            }
        }
    }
}
